__author__ = 'Wir'
import pygame


pygame.init()
xsize = 1024
ysize = 768
screen = pygame.display.set_mode((xsize, ysize))
done = False
x = 1024/2
y = 768-65
clock = pygame.time.Clock()
surface = pygame.Surface((100, 100), pygame.SRCALPHA)
image = pygame.image.load('ball.png')
shot_obj  = None
shot_objx = 0;
shot_objy = 0;

while not done:

        # will block execution until 1/60 seconds have passed
        # since the previous time clock.tick was called.
        clock.tick(60)
        for event in pygame.event.get():
                if event.type == pygame.QUIT:
                        done = True

        #Spiel
        screen.fill((0, 0, 0))
        #pygame.draw.rect(screen, (255,0,0), pygame.Rect(x,y,20,20))
        screen.blit(pygame.image.load('ball.png'), (x, y))
        pressed = pygame.key.get_pressed()
        #if pressed[pygame.K_UP]: y -= 3
        #if pressed[pygame.K_DOWN]: y += 3
        if pressed[pygame.K_LEFT] and (x > 0):
            x -= 10
        if pressed[pygame.K_RIGHT] and (x < xsize-50):
            x += 10

        if pressed[pygame.K_UP] and (shot_obj == None):
            shot_objx = x+25;
            shot_objy = y+25;
            shot_obj = screen.blit(pygame.image.load('bullet2.png'), (shot_objx, shot_objy))



        if shot_obj:
            shot_objy -= 20
            img = pygame.image.load('bullet2.png')
            img = pygame.transform.scale(img, (10,42) )
            shot_obj = screen.blit(img, (shot_objx, shot_objy))

            if shot_objx > xsize or shot_objy > ysize:
                shot_obj = None
            if shot_objx < 0 or shot_objy < 0:
                shot_obj = None


        pygame.display.update() #Screen refresh
